import { useEffect, useRef } from "react"
import * as echarts from 'echarts';

const BarChart = ({title}) => {
    const chartRef = useRef(null)
    // 确保dom可用
    useEffect(() => {
        const chartDom = chartRef.current;
        const myChart = echarts.init(chartDom);
        const option = {
            title: {
                text: title
            },
            xAxis: {
                type: 'category',
                data: ['Vue', 'Angular', 'React']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data: [120, 200, 150],
                    type: 'bar'
                }
            ]
        };
        option && myChart.setOption(option);
    }, [])
    return <div ref={chartRef} style={{ width: '500px', height: '400px' }}></div>
}
export default BarChart
